const cloud = require('wx-server-sdk');

cloud.init({
    env: cloud.DYNAMIC_CURRENT_ENV
});
const db = cloud.database();
const _ = db.command

exports.getRoom = async (event, context) => {
    let res = await db.collection("room").where({
        sender: _.and([_.all(event.sender), _.size(event.sender.length)])
    }).limit(1).get()
    if (res.data.length==0) {
        let res_2 = await db.collection("room").add({
            data: {
                sender: event.sender
            }
        })
        console.log(res_2)
        return res_2._id
    } else {
        return res.data[0]._id
    }
}